package com.gf.nams.util.page;

import java.util.List;
import java.util.concurrent.Callable;

public class PaginationUtil {
	
	public static <T> PagedList<T> pagedQuery(Page page, Callable<List<T>> command) {
		try {
			PaginationContext pc = PaginationContext.current();
			pc.setPagingParameter(page);

			List<T> data = command.call();

			return new PagedList<T>(pc.getPagingParameter(), data);
		} catch (Exception e) {
			throw new RuntimeException(e);
		} finally {
			PaginationContext.clear();
		}
	}

}
